package cn.itcast.one2many;

import org.apache.rocketmq.client.producer.DefaultMQProducer;
import org.apache.rocketmq.client.producer.SendResult;
import org.apache.rocketmq.common.message.Message;

// 生产者
public class Producer {
    public static void main(String[] args) throws Exception {
        // 1. 谁来发?
        DefaultMQProducer producer = new DefaultMQProducer("group1");

        // 2. 发给谁?
        producer.setNamesrvAddr("127.0.0.1:9876");
        producer.start();

        // 3. 怎么发？
        // 4. 发什么?
        Message message = new Message("topic1", "hello world".getBytes());
        for (int i = 0; i < 10; i++) {
            SendResult send = producer.send(message);
            // 5. 发的结果是什么？
            System.out.println(send);
        }

        // 6. 打扫战场？
        producer.shutdown();
    }
}